<template>
<div>
	<content_top title="公司主体列表"></content_top>
	
	<div class="g_box">
		<div class="g_head">
			<h3>数据列表</h3>
			<div class="g_box_right">
				<ButtonGroup class="g_act_box">
					<Button @click="add">添加</Button>
				</ButtonGroup>
			</div>
		</div>
		<div class="g_box_con">
			<Table :loading="loading" ref="table" :columns="Columns" :data="list" style="width: 100%;" size="small" :border="true" ></Table>
			<div style="font-size: 14px;overflow: hidden;padding: 10px;">
				<div style="float:left;">
					<Select v-model="batch_act" style="width:100px;;">
						<Option value="" >请选择</Option>
						<Option value="enable">显示</Option>
						<Option value="disconnected">隐藏</Option>
						<Option value="delete" >删除</Option>
					</Select>
					<Button @click="batch_action">确定</Button>
				</div>
				<div style="float:right;">
					<Page :total="count" show-elevator show-total @on-change="goto_page"  />
				</div>
			</div>
		</div>
	</div>
<!-- 编辑币种 -->
	
	<info v-model="einfo.show" :cinfo="einfo.info" @success="success_info"></info>
</div>
</template>

<script>
import info from './info';

export default {
    name: 'system_list',
    data () {
		let self = this;
        return {
			einfo:{
				show: false,
				id:0,
				info:{}
			},
            Columns: [
				{
					type: 'selection',
					width: 80,
					align: 'center'
				},
				{
                    title: '排序',
					key: 'sort',
					width: 100,
					align: 'center'
                },
				{
                    title: '所在区域',
					key: 'name',
					width: 400,
					align: 'center'
                },
				{
                    title: '缩写',
					key: 'sx_name',
					width: 200,
					align: 'center'
                },
				{
                    title: '是否显示',
					key: 'is_enable',
					width: 200,
					align: 'center',
					render: (h, params) => {
						return h('i-switch',{
							props:{
								'true-value':1,
								'false-value':0,
								value:parseInt(params.row.is_enable)
							},
							on:{
								'on-change':function(val){
									
									self.set_enable(params.row.id,val);
								}
							}
						});
					}
                },
				{
					title:'操作',
					key: 'action',
					align: 'center',
					render: (h, params) => {
						return h('div', [
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									marginRight: '5px',
								},
								on: {
									click: () => {
										self.edit(params.row);
									}
								}
							}, '编辑'),
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									
								},
								on: {
									click: () => {
										self.remove(params.row.id);
									}
								}
							}, '删除')
						]);
					}
				}
            ],
            list:[],
			page:1,
			count:0,
			loading:false,
			filter:{
				
			},
			batch_act: '',
        };
	},
	components:{
		info,
	},
	created(){
		
		this.load_data();
	},
    computed: {
       
    },
	methods:{
		load_data(){
			var self = this;
			
			var postdata = {
				page:this.page,
			}
			
			Whttp.load('User/Region/get_list',postdata,function(result){
				self.list = result.list;
				self.count = parseInt(result.count);
			});
		},
		qurey(){
			this.load_data();
		},
		goto_page(page){
			this.page = page;
			this.load_data();
		},
		edit(row){
			this.einfo.info = this._getData(row);
			this.einfo.show = true;
		},
		add(){
			this.einfo.info = {};
			this.einfo.show = true;
		},
		remove(id){
			var self = this;
			if(!confirm('是否删除')){
				return false;
			}
			var postdata = {
				id:id
			};
			Whttp.load('User/Region/del',postdata,function(result){
				self.load_data();
				self.$Message.info('删除成功');
			});
		},
		batch_action(){
			
			var ids = [];
			if(this.batch_act=='delete'){
				if(!confirm('是否批量删除')){
					return false;
				}
			}
			
			var sels = this.$refs['table'].getSelection();
			
			for(var i=0;i<sels.length;i++){
				ids.push(sels[i].id);
			}
			
			var self = this;
			var postdata = {
				ids:ids,
				act:this.batch_act
			};
			Whttp.load('User/Region/batch_act',postdata,function(result){
				self.$Message.info('操作成功');
				self.load_data();
				self.batch_act = '';
			});
			
		},
		success_info(res){
			this.page = 1;
			this.load_data();
		},
		set_enable(id,status){
			var self = this;
			var postdata = {
				id:id,
				status:status
			};
			Whttp.load('User/Region/set_enable',postdata,function(result){
				self.$Message.info('操作成功');
			});
		}
	}
};
</script>
<style scoped>
.price{
	color: red;
    margin: 0 5px;
}
</style>